package com.service.impl;

import com.entity.Role;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.RoleMapper;
import com.service.RoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.utils.PageObject;
import com.vo.MaterialVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author aiou
 * @since 2025-06-12
 */
@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;

    //添加角色信息
    @Override
    public boolean save(Role role) {
        return roleMapper.insert(role);
    }

    //修改角色信息
    @Override
    public boolean updateById(Role role) {
        return roleMapper.updateById(role);
    }

    //删除角色信息
    @Override
    public boolean removeByRoleId(Integer roleId) {
        return roleMapper.deleteByRoleId(roleId);
    }

    //分页查询
    @Override
    public PageObject<Role> roleList(PageObject pageObject) {
        //开始分页
        PageHelper.startPage(pageObject.getCurrent(),pageObject.getSize());
        //查询数据
        List<Role> list = roleMapper.list();
        //PageHelper包装数据
        PageInfo<Role> pageInfo = new PageInfo<>(list);
        //将数据封装进PageResult
        PageObject<Role> RolePageResult
                = new PageObject<>(pageInfo.getPageNum(), pageInfo.getPageSize(), pageInfo.getTotal(), pageInfo.getList());
        return RolePageResult;
    }
}
